#include <iostream>
using namespace std;
const int N=2e5+10;
typedef long long LL;
int a[N];
int n;
LL dfs(int left,int right)
{
    if(left>=right)return a[left];
    int mid=(right+left)/2;
    int ret=max(dfs(left,mid),dfs(mid+1,right));
    int sum=a[mid];
    int lsum=a[mid];
    for(int i=mid-1;i>=left;i--)
    {
        sum+=a[i];
        lsum=max(lsum,sum);
    }
    sum=a[mid+1];int rsum=a[mid+1];
    for(int i=mid+2;i<=right;i++)
    {
        sum+=a[i];
        rsum=max(rsum,sum);
    }
    return max(ret,rsum+lsum);

}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    cout<<dfs(1,n);
    return 0;
}
